﻿#pragma once

#include "qlib/geo/label.h"
#include "qlib/geo/polygon.h"

namespace qlib {
class Ruler;
using RulerPtrArray = std::vector<std::shared_ptr<Ruler>>;
class QLIB_API Ruler {
 public:
  Ruler();
  Ruler(Vec2d _start, Vec2d _end);

  Ruler(const Ruler& oth);
  Ruler& operator=(const Ruler& other);

  using s_ptr = std::shared_ptr<Ruler>;
  template <typename... Args>
  static s_ptr create(Args... args) {
    return std::make_shared<Ruler>(args...);
  }
  // template <>
  static s_ptr create() {
    return std::make_shared<Ruler>();
  }
  static s_ptr create(const Ruler& value) { return std::make_shared<Ruler>(value); }

  s_ptr copy() const;

  void rotate(double angle, Vec2d center);
  void translate(double dx, double dy);
  void mirror(Vec2d p0, Vec2d p1);

  // double getRotation();
  void setRotation(double rotation);

  Vec2dArray get_scale_lines();
  Vec2dArray get_label_lines();
  Vec2dArray get_lines(const Vec2d& p1, const Vec2d& p2, double step, double unit_scale);

  Polygon::s_ptr to_polygon();

  Vec2dArray bounding_box_points() { return box_to_points(bounding_box()); };
  Vec2dArray bounding_box();

  Vec2dArray points() { return qlib::Vec2dArray{start, end}; }

  Vec2dArray render_aabb();
  Vec2dArray render_poly();
  Vec2dArray render_absorp();

  int step{10};
  double hLength{1};

  Vec2d center{0, 0};
  Vec2d start{0, 0};
  Vec2d end{0, 0};

  float length;

  uint32_t layer{0};
  uint32_t datatype{0};

  Vec2dArray box;
  Vec2dArray lines;  // 渲染缓存

  PropertyArray properties;  ///< 属性对象
  Repetition repetition;     ///< 重复对象
};
}  // namespace qlib